//
//  BCHttpResponseModel.m
//  BCBaseNetworking
//
//  Created by Basic on 16/3/22.
//  网络请求 response 通用基类
//

#import "BCHttpResponseModel.h"

@implementation BCHttpResponseMsgModel
+ (NSDictionary *)modelCustomPropertyMapper {
    return @{
        @"type": @[@"isPopup", @"type"]
    };
}

- (BOOL)canShow {
    return (_type != kBCHttpResponse_MsgTypeNone);
}

@end


@implementation BCHttpResponseModel

+ (NSDictionary *)modelCustomPropertyMapper {
    return @{
        @"message": @[@"msg", @"message"]
    };
}

- (void)bc_loadDefaultResponse
{
    if (self.bc_statusCode != 200) {
        self.success = NO;
        self.popup.type = kBCHttpResponse_MsgTypeToast;
        self.popup.message = @"服务连接失败";
    }
}

#pragma mark - getter
- (BCHttpResponseMsgModel *)popup {
    if (!_popup) {
        _popup = [[BCHttpResponseMsgModel alloc] init];
        _popup.message = @"";
    }

    return _popup;
}

- (NSString *)message {
    //错误提示兼容
    if (_message.length <= 0 && _popup.message.length > 0) {
        _message = _popup.message;
    }

    // 兼容空消息
    return _message ? : @"";
}

@end
